package com.wnhz.work.yz.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.download.ImageDownloader;
import com.wnhz.work.yz.R;

import java.util.List;

/**
 * 作者： zxb
 * 日期： 2016/12/28
 * 描述： 售后图片添加的adapter
 */
public class ServiceRecycleAdapter extends RecyclerView.Adapter<ServiceRecycleAdapter.TitleViewHolder> {
    private Context context;
    private List<String> nameList;
    private View.OnClickListener onClickListener;
    private View.OnLongClickListener longClickListener;

    public ServiceRecycleAdapter(Context context, List<String> nameList, View.OnClickListener onClickListener, View.OnLongClickListener longClickListener) {
        this.context = context;
        this.nameList = nameList;
        this.onClickListener = onClickListener;
        this.longClickListener = longClickListener;
    }

    @Override
    public TitleViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_rc_service, parent, false);
        TitleViewHolder holder = new TitleViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(TitleViewHolder holder, int position) {

        DisplayImageOptions options = new DisplayImageOptions.Builder().cacheInMemory(true).cacheOnDisk(true)
                // .displayer(new CircleBitmapDisplayer())
                .build();
        String drawableUrl;
        if (position == nameList.size() - 1) {
            drawableUrl = ImageDownloader.Scheme.DRAWABLE.wrap(nameList.get(position));
        } else {
            drawableUrl = ImageDownloader.Scheme.FILE.wrap(nameList.get(position));
        }

        System.out.println("onBindViewHolder:" + drawableUrl);
        ImageLoader.getInstance().displayImage(drawableUrl, holder.image, options);

        holder.image.setOnClickListener(onClickListener);
        holder.image.setOnLongClickListener(longClickListener);
        holder.image.setTag(position);
    }

    @Override
    public int getItemCount() {
        return nameList.size();
    }

    class TitleViewHolder extends RecyclerView.ViewHolder {
        ImageView image;


        public TitleViewHolder(View view) {
            super(view);

            image = (ImageView) view.findViewById(R.id.iv_rc_service);

        }
    }
}
